// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "WorldConnectable.h"
#include "WorldRoadParts.h"
#include "WorldEntityAxis.h"

class FWorldJunction;
class FWorldRoadConnectInfo
{
public:
	FWorldContactPoint contactpoint;
	std::vector<std::pair<int, int>> laneconnections;
};
/**
 * An entity of a road.
 */
class FWorldRoad : public FWorldConnectable
{

public:

	using Ptr = std::shared_ptr<FWorldRoad>;
	using Super = FWorldConnectable;

	FWorldEntityProperty< double >									Length;
	FWorldEntityReference< FWorldJunction >							Junction;
	FWorldEntityPartReference< FWorldRoadLink, 0 >					Link;
	FWorldEntityPartArrayReference< FWorldRoadType, 0, INT_MAX >	Type;
	FWorldEntityPartReference< FWorldPlanView, 1 >					PlanView;
	FWorldEntityPartReference< FWorldRoadElevationProfile, 0 >		ElevationProfile;
	FWorldEntityPartReference< FWorldRoadLateralProfile, 0 >		LateralProfile;
	FWorldEntityPartReference< FWorldLanes, 1 >						Lanes;
	FWorldEntityPartReference< FWorldRoadObjects, 0 >				Objects;
	FWorldEntityPartReference< FWorldRoadSignals, 0 >				Signals;
	FWorldEntityPartReference< FWorldRoadSurface, 0 >				Surface;

	FWorldEntityAxis	Axis;

	//this is used to store link road parsed from junction bool is the contact points
	std::vector<std::pair<FWorldRoad*, FWorldRoadConnectInfo>> predecessors;
	std::vector<std::pair<FWorldRoad*, FWorldRoadConnectInfo>> sucessors;

public:

	FWorldRoad();
	FWorldRoad(const json& j);
	~FWorldRoad() override;

	void Resolve(FWorldEntityReferencing& referencing) override;

	WORLD_ENTITY_META_DECLARE(FWorldRoad)

};
